#!/bin/sh
if [ "$1" = "stop" ]; then
  ps ax| grep "remoteconnect@sipman.net"|grep -v grep | while read PID REST
  do
    kill $PID
  done
  exit
fi
if [ "`pidof privoxy`" = "" ]; then
  /etc/init.d/privoxy restart
fi
TEST="`ps ax| grep "remoteconnect@sipman.net"|grep -v grep`"
#echo "- $TEST -"
if [ "$TEST" = "" ]; then
  echo "Starting tunnel at `date`."
  /var/sipman3/main/maint/connect-sipman.sh 
  echo "Terminating tunnel at `date`."
fi
